#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int N = 1e5 + 10, M = 2e6 + 10;
vector<pii> edges[N];
struct node
{
    int x, y, z;
}e[M];
int h[N];
int fa[N];
int find(int x)
{
    return fa[x] == x ? x : fa[x] = find(fa[x]);
}
ll ret, cnt;
int n, m;
bool st[N];
int pos;
void dfs(int x)
{
    cnt++;
    st[x] = true;
    for (auto& s : edges[x])
    {
        pos++;
        int v = s.first;
        int k = s.second;
        e[pos].x = x;
        e[pos].y = v;
        e[pos].z = k;
        if (!st[v])
        {
            dfs(v);
        }
    }
}
bool cmp(node& s1, node& s2)
{
    int w1 = s1.y;
    int w2 = s2.y;
    if (h[w1] != h[w2])
    {
        return h[w1] > h[w2];
    }
    else
    {
        return s1.z < s2.z;
    }
}
void kk()
{
    for (int i = 1; i <= n; i++)
    {
        fa[i] = i;
    }
    sort(e + 1, e + 1 + pos, cmp);
    for (int i = 1; i <= pos; i++)
    {
        int x = e[i].x;
        int y = e[i].y;
        int z = e[i].z;
        int fx = find(x);
        int fy = find(y);
        if (fx != fy)
        {
            ret += z;
            fa[fx] = fy;
        }
    }
}
int main()
{
    cin >> n >> m;
    for (int i = 1; i <= n; i++)
    {
        cin >> h[i];
    }
    for (int i = 1; i <= m; i++)
    {
        int a, b, c;
        cin >> a >> b >> c;
        if (h[a] >= h[b])
        {
            edges[a].push_back({ b,c });
        }
        if (h[a] <= h[b])
        {
            edges[b].push_back({ a,c });
        }
    }
    dfs(1);
    kk();
    cout << cnt << " " << ret;
    return 0;
}